package com.chinasofti.project.web;

import javax.servlet.http.HttpSession;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.chinasofti.project.dal.model.custom.BzProduct;
import com.chinasofti.project.service.itemCategory.ItemCategoryService;
import com.chinasofti.project.service.itemCategory.customForm.SqlSearchForm;
import com.chinasofti.project.web.form.SearchForm;

@Controller
public class ItemCategoryController {
	@Autowired
	ItemCategoryService itemCategoryService;

	// 搜索
	@RequestMapping(value = "category", method = RequestMethod.POST)
	public String toLineItem(SearchForm searchForm, ModelMap mm, HttpSession httpSession) {
		SqlSearchForm sqlSearchForm = new SqlSearchForm();
		BeanUtils.copyProperties(searchForm, sqlSearchForm);
		mm.put("resultForm", itemCategoryService.selectByProduct(sqlSearchForm));
		mm.put("searchName", searchForm.getSearchName());
		mm.put("pageIdx", searchForm.getPageIdx());
		mm.put("threeClassification", searchForm.getThreeClassification());
		mm.put("shoppingCatNum", httpSession.getAttribute("shoppingCatNum"));
		return "itemCategory";
	}

	// 搜索
	@RequestMapping("category")
	public String toItemCategory(String threeClassification, String searchName, int pageIdx, double startPrice,
			double endPrice, ModelMap mm, HttpSession httpSession) {
		SqlSearchForm sqlSearchForm = new SqlSearchForm();
		sqlSearchForm.setThreeClassification(threeClassification);
		sqlSearchForm.setPageIdx(pageIdx);
		sqlSearchForm.setSearchName(searchName);
		sqlSearchForm.setStartPrice(startPrice);
		sqlSearchForm.setEndPrice(endPrice);
		mm.put("resultForm", itemCategoryService.selectByProduct(sqlSearchForm));
		mm.put("threeClassification", threeClassification);
		mm.put("shoppingCatNum", httpSession.getAttribute("shoppingCatNum"));
		return "itemCategory";
	}

	// 详情
	@RequestMapping("bookIndex")
	public String toItemShow1(int productId, ModelMap mm, HttpSession httpSession) {
		BzProduct resultForm = itemCategoryService.selectByProductId(productId);
		mm.put("resultForm", resultForm);
		mm.put("shoppingCatNum", httpSession.getAttribute("shoppingCatNum"));
		return "itemShow";
	}

}
